package cn.com.oceansoft.business.os.api.qrcode.service.impl;


import cn.com.oceansoft.business.os.api.qrcode.domain.CheckIn;
import cn.com.oceansoft.business.os.api.qrcode.domain.User;
import cn.com.oceansoft.business.os.api.qrcode.persistence.IQrcodeMapper;
import cn.com.oceansoft.business.os.api.qrcode.service.IQrcodeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 系统字典数据库操作映射器
 *
 * @author: chenw
 * @time: 2014/5/26 0026 下午 19:28
 */
@Service
public class QrcodeServiceImpl implements IQrcodeService {
    @Resource
    private IQrcodeMapper iQrcodeMapper;

    @Override
    public User findUserByIdAndName(Map<String, String> param) {
        return iQrcodeMapper.findUserByIdAndName(param);
    }

    @Override
    public String saveCheckIn(CheckIn checkIn) {
        int dbid = iQrcodeMapper.getDbid();
        String LotteryNumbe="";
        if(dbid<10){
            LotteryNumbe = "00"+dbid;
        }else if(dbid>=10&&dbid<100){
            LotteryNumbe = "0"+dbid;
        }else{
            LotteryNumbe=""+dbid;
        }
        checkIn.setId(dbid);
        checkIn.setLotteryNumber(LotteryNumbe);
        iQrcodeMapper.saveCheckIn(checkIn);
        return LotteryNumbe;
    }

    @Override
    public boolean checkUserLogin(String openId) {
        int i =  iQrcodeMapper.checkUserLogin(openId);
        if(i>0){
            return false;
        }
        return true;
    }

    @Override
    public List<CheckIn> findtAwardList(String awardid,String votes) {
        if("41".equals(awardid)){
            return iQrcodeMapper.findAward(awardid);
        }
        return iQrcodeMapper.findtAwardList(awardid,votes);
    }

    @Override
    public void saveAwardResult(String userid, String awardid) {
        iQrcodeMapper.saveAwardResult(userid,awardid);
    }

    @Override
    public int checkIsCheckIn(User user) {
        return iQrcodeMapper.checkIsCheckIn(user);
    }

    @Override
    public CheckIn findCheckInByOpenId(String openId) {
        return iQrcodeMapper.findCheckInByOpenId(openId);
    }
}
